#include <iostream>
#include <string>

class Switch {
public:
    virtual ~Switch() = default;
    virtual void buy() = 0;
    virtual void sell() {}
};

class JapenSwitch : public Switch {
public:
    void buy () { std::cout << "japen switch" << std::endl; }
};

class Proxy : public Switch {
public:
    Proxy() : m_switch(nullptr) {}
    ~Proxy() { if (m_switch) delete m_switch; }

    virtual void buy() {
        if (m_switch == nullptr) m_switch = new JapenSwitch();

        m_switch->buy();
    }

private:
    JapenSwitch* m_switch;
};

int main(int argc, const char **argv) {
    Proxy p;
    p.buy();
    return 0;
}
